Action<int, string> action1 = (int i, string str) => {}; var del1 = new Action<int, string>((int i, string str) => {}); Console.WriteLine(ActionHasDelegate(action1, del1)); // Output: False action1 += del1; Console.WriteLine(ActionHasDelegate(action1, del1)); // Output: True }
staticboolActionHasDelegate<T>(T action, Delegate del) where T : Delegate { foreach (var d in action.GetInvocationList()) { if (d == del) { returntrue; } } returnfalse; }